import React, { PureComponent } from 'react';
import { Table } from 'antd';
import { connect } from 'dva';
import styles from './index.less';

@connect(({ recommendRecord, loading }) => ({
  recommendRecord,
  loading: loading.models.recommendRecord,
}))
class RecommendRecordTable extends PureComponent {
  static smartTypes = [
    { text: '结果1（撞库通过）', value: 1 },
    { text: '结果2（条件筛选）', value: 2 },
    { text: '结果3（筛选无结果）', value: 3 },
  ];

  ident = [
    { text: '未认证', value: 0 },
    { text: '认证', value: 1 },
  ];

  handleTableChange = (pagination, filters, sorter) => {
    this.props.onChange(pagination, filters, sorter);
  }

  render() {
    const { data: { list, pagination }, dynmicColumns, dynmicChannels, loading } = this.props;
    const columns = [{
      title: '注册时间',
      dataIndex: 'record_registerTime',
    }, {
      title: '提交资料时间',
      dataIndex: 'record_addTime',
    }, {
      title: '来源渠道',
      dataIndex: 'record_appMgr',
      render: (val) => {
        // eslint-disable-next-line camelcase
        let result = '';
        dynmicChannels.every((type) => {
          if (type.channelId === val) {
            result = type.channelName;
            return false;
          }
          return true;
        });
        return `${result}`;
      },
    },
    ];
    dynmicColumns.forEach((colum) => {
      const col = {};
      col.title = colum.smart_type;
      col.dataIndex = `record_recommend_id_${colum.smart_id}`;
      columns.push(col);
    });
    columns.push({
      title: '基本信息状态',
      dataIndex: 'record_baseIdent',
      render: (val) => {
        // eslint-disable-next-line camelcase
        const smart_Types = this.ident;
        let result = '';
        smart_Types.every((type) => {
          if (type.value === val) {
            result = type.text;
            return false;
          }
          return true;
        });
        return `${result}`;
      },
    });
    columns.push({
      title: '身份证状态',
      dataIndex: 'record_idIdent',
      render: (val) => {
        // eslint-disable-next-line camelcase
        const smart_Types = this.ident;
        let result = '';
        smart_Types.every((type) => {
          if (type.value === val) {
            result = type.text;
            return false;
          }
          return true;
        });
        return `${result}`;
      },
    });
    columns.push({
      title: '智能推荐类别',
      dataIndex: 'record_type',
      render: (val) => {
        // eslint-disable-next-line camelcase
        const smart_Types = RecommendRecordTable.smartTypes;
        let result = '';
        smart_Types.every((type) => {
          if (type.value === val) {
            result = type.text;
            return false;
          }
          return true;
        });
        return `${result}`;
      },
    });
    columns.push({
      title: '推荐产品数量',
      dataIndex: 'record_num',
    });
    columns.push({
      title: '用户申请数量',
      dataIndex: 'record_apply',
    });

    const paginationProps = {
      showSizeChanger: true,
      showQuickJumper: true,
      ...pagination,
    };


    return (
      <div className={styles.standardTable}>
        <Table
          className={styles.tableTr}
          loading={loading}
          dataSource={list}
          columns={columns}
          pagination={paginationProps}
          onChange={this.handleTableChange}
        />
      </div>
    );
  }
}

export default RecommendRecordTable;
